﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ThridGroup.ERP.DTO;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace ThridGroup.ERP.HumanResources
{
    public class InterviewService : ApplicationService, InterviewIService
    {
        /// <summary>
        /// 面试仓储
        /// </summary>
        private readonly IRepository<InterviewMenagement, int> _interviewServices;
        public InterviewService(IRepository<InterviewMenagement, int> interviewServices)
        {
            _interviewServices = interviewServices;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="interview">实体</param>
        /// <returns>返回任务</returns>
        public async Task<int> AddInterview(InterviewDTO interview)
        {
            var addinterview = ObjectMapper.Map<InterviewDTO, InterviewMenagement>(interview);
            var interviewlist = await _interviewServices.InsertAsync(addinterview);
            return interviewlist == null ? 0 : 1;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="interviewId">主键</param>
        /// <returns>返回任务</returns>
        public async Task<int> DeleteInterview(int interviewId)
        {
            var result = _interviewServices.DeleteDirectAsync(c=>c.Id == interviewId);
            return result == null ? 0 : 1;
        }
        /// <summary>
        /// 返回单条数据
        /// </summary>
        /// <param name="interviewId">主键</param>
        /// <returns>返回任务</returns>
        public async Task<InterviewDTO> FanInterview(int interviewId)
        {
            var result = await _interviewServices.FindAsync(c => c.Id == interviewId);
            var list = ObjectMapper.Map<InterviewMenagement, InterviewDTO>(result);
            return list;
        }
        /// <summary>
        /// 获取面试列表
        /// </summary>
        /// <returns>返回任务</returns>
        public async Task<List<InterviewDTO>> GetInterview()
        {
            var list = await _interviewServices.GetListAsync();
            var result = ObjectMapper.Map<List<InterviewMenagement>, List<InterviewDTO>>(list);
            return result;
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="interview">实体</param>
        /// <returns>返回任务</returns>
        public async Task<int> UpdateInterview(InterviewDTO interview)
        {
            var updinterview = ObjectMapper.Map<InterviewDTO, InterviewMenagement>(interview);
            var interviewlist = await _interviewServices.UpdateAsync(updinterview);
            return interviewlist == null ? 0 : 1;
        }
    }
}
